#include "Ball.h"

Ball::Ball(void)
{
	radius = 1.0;
	color = vector3(1.0, 1.0, 1.0);
	bounced = false;
	maxVelocity = 400;
}


Ball::~Ball(void)
{
}

Ball::Ball(double r, double m)
{
	radius = r;
	color = vector3(1.0, 1.0, 1.0);
	transform.mass = m;
	transform.invMass = 1/m;
	transform.inertia = (2*m*r*r)/5;
	transform.invInertia = 1/transform.inertia;
	bounced = false;
	maxVelocity = 400;
}

void Ball::Render(void)
{
	glLoadIdentity();
	DrawTools::drawCircle(transform.position, radius, color);
}

void Ball::Update(double t, double dt)
{
	previous = transform;
	Integrate(transform, t, dt);

	if (transform.momentum.length()/transform.mass > maxVelocity)
	{
		transform.momentum = transform.momentum.normalized() * maxVelocity;
	}
}